<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<% String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>优车处置-借款维护</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div>
        <form id="carCostInfoForm">
            <div class="fieldset1 tabel_col clearFix">
                <div class="Hide">
                    <input name="carId" id="carId" type="text" value="${carId}">
                    <input name="dealCostId" id="dealCostId" type="text" value="${dealCost.id}">
                    <input name="sysEmpBankId" id="sysEmpBankId" type="text" value="${dealCost.sysEmpBankId}">
                </div>
                <div class="fieldBox col_50">
                    <div class="label">借款金额<span class="requiredSymbol">*</span></div>
                    <div class="field">
                        <input name="costAmt" id="costAmt" type="text" class="ui-textbox" ligerui="width: 160" value="<fmt:formatNumber value="${dealCost.costAmt==null?null:dealCost.costAmt/100}" pattern="0.##"/>" validate="{required:true,amount:true}">
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">借款类型<span class="requiredSymbol">*</span></div>
                    <div class="field">
                        <input name="loanTypCd" id="loanTypCd" data-value="${dealCost.loanTypCd}" placeholder="请选择" ltype="combobox" ligerui="width: 160" validate="{required:true}"/>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">付款方式<span class="requiredSymbol">*</span></div>
                    <div class="field">
                        <input name="payTypCd" id="payTypCd" data-value="${dealCost.payTypCd}" placeholder="请选择" ltype="combobox" ligerui="width: 160" validate="{required:true}"/>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">收款账户<span class="requiredSymbol">*</span></div>
                    <div class="field">
                        <div class="triggerPop1">
                            <input name="rcptUnt" id="rcptUnt" type="text" class="ui-textbox" value="${dealCost.empBankAcc.rcptUnt}" ligerui="width: 160" readonly />
                        </div>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">收款账号<span class="requiredSymbol">*</span></div>
                    <div class="field">
                        <div class="triggerPop1">
                            <input name="accNo" id="accNo" type="text" class="ui-textbox" value="${dealCost.empBankAcc.accNo}" ligerui="width: 160" readonly />
                        </div>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">开户银行<span class="requiredSymbol">*</span></div>
                    <div class="field">
                        <input name="bkNm" id="bkNm" type="text" class="ui-textbox" value="${dealCost.empBankAcc.bkNm}" ligerui="width: 160" readonly />
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">备注</div>
                    <div class="field">
                        <textarea name="costRem" id="costRem" rows="4" class="l-textarea" style="width:98%" value="">${dealCost.costRem}</textarea>
                    </div>
                </div>


                <div class="caption">
                    <div class="btnsBox posL">
                        <span class="sq-button sq-button-round" onclick="toAddBankAcc()">新增账户</span>
                    </div>
                    <span class="title">收款账户</span>
                </div>
                <div class="fieldBox col_100">
                    <div class="sqPanel">
                        <div id="ligerGridBank" class="sq-grid"></div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    var basePath = "<%=path%>";
    var ligerGridBank = null;
    $(function () {
        $("#carCostInfoForm").ligerForm({
            validate: true
        });

        $("#loanTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            width: 160,
            data: ${loanTypList}
        });

        $("#payTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            width: 160,
            data: ${payTypList}
        });

        ligerGridBank = $("#ligerGridBank").ligerGrid({
            url: basePath + '/capital/finance/loan/apply/bankAcc/initList.do',
            method: 'get',
            columns: [
                {display: '收款账户', name: 'rcptUnt', width: 180, align: 'center', enabledSort: false},
                {display: '收款账户', name: 'accNo', width: 180, align: 'center', enabledSort: false},
                {display: '开户银行', name: 'bkNm', width: 180, align: 'center', enabledSort: false},
                {display: '开户行号', name: 'bkNo', width: 180, align: 'center', enabledSort: false}
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            //height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: true,
            isSingleCheck: true,
            isChecked: function (rowdata) {
                if (rowdata.id == $("#sysEmpBankId").val())
                    return true;
                return false;
            },
            onCheckRow: function (checked, data, rowid) {
                if (checked) {
                    $("#rcptUnt").val(data.rcptUnt);
                    $("#accNo").val(data.accNo);
                    $("#bkNm").val(data.bkNm);
                    $("#sysEmpBankId").val(data.id);
                } else {
                    $("#rcptUnt").val('');
                    $("#accNo").val('');
                    $("#bkNm").val('');
                    $("#sysEmpBankId").val('');
                }
            }
        });

        // 点击确认事件
        frameElement.dialog.onOk = function () {
            var form = liger.get("carCostInfoForm");
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false;
            }
            var sysEmpBankId = $("#sysEmpBankId").val();
            if (StringUtils.isEmpty(sysEmpBankId)) {
                $.ligerDialog.SQalert({content: "请选择一条收款账户信息！", SQ_type: "warning"});
                return false;
            }
            var data = form.getData();
            data.id = $("#dealCostId").val();
            data.loanApplyAmt = data.costAmt;
            var wait_dialog, url;
            if (StringUtils.isNotEmpty(data.id)) {
                url = "/ass/assTrailCarD/updateCarCost.do";
            } else {
                url = "/ass/assTrailCarD/addCarCost.do";
            }
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: basePath + url,
                beforeSend: function () {
                    wait_dialog = top.$.ligerDialog.SQalert({ content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting" });
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({
                            content: msg.info, SQ_showButtons: true, SQ_type: "success", onClose: function () {
                                frameElement.dialog.close();
                            }
                        });
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        };

    });

    function toAddBankAcc() {
        var onOk = function (item, Dialog) {
            if (Dialog.onOk) Dialog.onOk();
        };
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.open({
            width: 800,
            height: 380,
            title: '添加收款方信息',
            url: basePath + '/ass/ucardeal/toAddBankAccPage.do',
            buttons: [{
                text: "保存", type: 'ok', onclick: onOk
            }, {
                text: "关闭", type: 'cancel', onclick: onCancel, cls: 'l-dialog-btn-no'
            }],
            onClose: function() {
                ligerGridBank.reload();
            }
        });
    }

</script>
</body>
</html>